<template>
  <div style="margin: 20px;">
    <h1 style="text-align: center">发布新课程</h1>
    <el-steps :active="2" process-status="finish" align-center>
      <el-step title="填写课程基本信息"></el-step>
      <el-step title="创建课程大纲"></el-step>
      <el-step title="最终发布"></el-step>
    </el-steps>

    <div class="background">
      <div>
        <el-image :src="api+course.cover" style="height: 280px;"/>
      </div>
      <div class="description">
        <h1>{{ course.title }}</h1>
        <h3>共{{ course.lessonNum }}课时</h3>
        <h3>所属分类：{{ course.subjectParentIdTitle }}——{{ course.subjectIdTitle }}</h3>
        <h3>课程讲师：{{ course.teacherName }}</h3>
        <h1 style="color:red;">￥{{ course.price }}</h1>
      </div>
    </div>

    <el-button style="margin-top: 30px" @click="previous">返回修改</el-button>
    <el-button type="primary" @click="onPublish">发布课程</el-button>
  </div>
</template>

<script>

import {couGetById, couPublish} from '@/api/course'

export default {
  data() {
    return {
      courseId: this.$route.query.courseId,
      course: {},
      api: process.env.VUE_APP_BASE_API
    }
  },
  created() {
    couGetById(this.courseId).then(res => {
      this.course = res.data
    })
  },
  methods: {
    previous() {
      this.$router.push({ path: '/course/save', query: { courseId: this.courseId } })
    },
    onPublish() {
      couPublish(this.courseId).then(res => {
        if (res.code === 200) {
          this.$message.success('发布成功')
          this.$router.push('/course/list')
        } else {
          this.$message.error('发布失败')
        }
      })
    }
  }
}
</script>

<style>

.background {
  border: 1px dotted #666666;
  padding: 30px;
  background-color: #dddddd;
  float: left;
  width: 100%;
}

.background div {
  float: left;
}

.description {
  margin: 10px 30px;
}

</style>
